/*
 * @lc app=leetcode id=69 lang=cpp
 *
 * [69] Sqrt(x)
 */
class Solution {
public:
    int mySqrt(int x) {

        if (x < 1) {
            return 0;
        }

        long i = x;
        while(i * i > x) {
            i = (i + x/i)/2;
        }

        return i;
        
    }
};

